1 using System;
2 using
UnityEngine;
3
4 namespace
UnityStandardAssets.Water
5 {
6     
public enum WaterQuality
7     {
8         High =
2,
9         Medium =
1,
10         Low =
0,
11     }
12
13     
[ExecuteInEditMode]
14     
public class WaterBase : MonoBehaviour
15     {
16         
public Material sharedMaterial;
17         
public WaterQuality waterQuality = WaterQuality.High;
18         
public bool edgeBlend = true;
19
20
21         
public void UpdateShader()
22         {
23             
if (waterQuality > WaterQuality.Medium)
24             {
25                 sharedMaterial.shader.maximumLOD =
501;
26             }
27             
else if (waterQuality > WaterQuality.Low)
28             {
29                 sharedMaterial.shader.maximumLOD =
301;
30             }
31             
else
32             {
33                 sharedMaterial.shader.maximumLOD =
201;
34             }
35
36             
// If the system does not support depth textures (ie. NaCl), turn off edge bleeding,
37             
// as the shader will render everything as transparent if the depth texture is not valid.
38             
if (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth))
39             {
40                 edgeBlend =
false;
41             }
42
43             
if (edgeBlend)
44             {
45                 Shader.EnableKeyword(
"WATER_EDGEBLEND_ON");
46                 Shader.DisableKeyword(
"WATER_EDGEBLEND_OFF");
47                 
// just to make sure (some peeps might forget to add a water tile to the patches)
48                 
if (Camera.main)
49                 {
50                     Camera.main.depthTextureMode |= DepthTextureMode.Depth;
51                 }
52             }
53             
else
54             {
55                 Shader.EnableKeyword(
"WATER_EDGEBLEND_OFF");
56                 Shader.DisableKeyword(
"WATER_EDGEBLEND_ON");
57             }
58         }
59
60
61         
public void WaterTileBeingRendered(Transform tr, Camera currentCam)
62         {
63             
if (currentCam && edgeBlend)
64             {
65                 currentCam.depthTextureMode |= DepthTextureMode.Depth;
66             }
67         }
68
69
70         
public void Update()
71         {
72             
if (sharedMaterial)
73             {
74                 UpdateShader();
75             }
76         }
77     }
78 }


Gõ tìm kiếm nhanh...